package com.shaowin.rabbitMQ;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.util.concurrent.TimeoutException;

/**
 * Created by chenshaowen on 2018/1/24.
 */
public class Send {
    private final static String QUEUE_NAME = "hello";

    public static void main(String[] argv) throws java.io.IOException, TimeoutException, InterruptedException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("112.74.76.100");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        String message = "Hello World!";
        int i=1;
        //测试，为了方便查看web的变化
        while (true){
            channel.basicPublish("", QUEUE_NAME, null, (message+i).getBytes());
            i++;
            Thread.sleep(5000);
        }
//        System.out.println(" [x] Sent '" + message + "'");
//
//        channel.close();
//        connection.close();
    }
}